<?php
session_start();
include("utils.php");
$mode = $_POST['mode'];
if($mode=='create_advertise')
{
create_ad();
}
else
{
main_content("main();");
//main();
}

############################## function to update user account starts#########################
function create_ad(){
//echo "<script>alert('123')</script>";
//print_r($_REQUEST);

if($_REQUEST['ad_type']=='banner')
{
$select_mobile_ad_image="select * from temp_image_upload where user_id = '".$_SESSION['siteuserId']."' order by image_id desc";

$exe_mobile_ad_image=mysql_query($select_mobile_ad_image);
$row_mobile_ad_image=mysql_fetch_array($exe_mobile_ad_image);

$ad_image_name=$row_mobile_ad_image['image_name'];
//echo "<script>alert('".$ad_image_name."')</script>";
mysql_query("delete from temp_image_upload where user_id = '".$_SESSION['siteuserId']."'");
}
################################ starts ################
$str_country='';
			for($i=0;$i<count($_REQUEST[country_mobile]);$i++)
			{
			if($_REQUEST[country_mobile][$i] != 0 || $_REQUEST[country_mobile][$i] != ''){
			
			if(count($_REQUEST[country_mobile])>1)
			{
				if($i==count($_POST[country_mobile])-1)
				{
					$str_country.=$_REQUEST[country_mobile][$i];
				}
				else
				{
					$str_country.=$_REQUEST[country_mobile][$i].",";
				}
			}
			else
			{
				$str_country.=$_REQUEST[country_mobile][$i];
			}
			}
			}

//echo "<script>alert('".$str_country."')</script>";
############################### ends ####################

if($_REQUEST['ad_type']=='text')
{
	$insert_create_ad="insert into create_mobile_ad set user_id = '".$_SESSION['siteuserId']."', ad_type = '".$_REQUEST['ad_type']."', ad_name = '".$_REQUEST['ad_name']."', bid_price = '".$_REQUEST['bid_price']."', ad_text = '".$_REQUEST['ad_text']."', link_to = '".$_REQUEST['destinationUrl']."', country_id = '".$str_country."'";
}
else if($_REQUEST['ad_type']=='banner')
{
	$insert_create_ad="insert into create_mobile_ad set user_id = '".$_SESSION['siteuserId']."', ad_type = '".$_REQUEST['ad_type']."', ad_name = '".$_REQUEST['ad_name']."', bid_price = '".$_REQUEST['bid_price']."', link_to = '".$_REQUEST['destinationUrl']."', country_id = '".$str_country."', ad_image = '".$ad_image_name."'";
}
mysql_query($insert_create_ad);
main_content("main();");
}
############################## function to update user account ends ############################

function main()
{
?>
<script language="JavaScript">

function create_ad()
{
	if(document.myAccountForm.bid_price.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_bidPrice').style.display='';
		document.getElementById('error_bidPrice').innerHTML="Please! Enter Bid Price.";
		return false;
	}

	if(isNaN(document.myAccountForm.bid_price.value))
	{
		if(document.getElementById('row_alert_bidPrice').style.display=='')
		{
			document.getElementById('error_bidPrice').innerHTML="Please! Enter Numeric Value As Bid Price.";
		}
		else if(document.getElementById('row_alert_bidPrice').style.display=='none')
		{
			document.getElementById('row_alert_bidPrice').style.display='';
			document.getElementById('error_bidPrice').innerHTML="Please! Enter Numeric Value As Bid Price.";
		}
		return false;
	}

	if(document.myAccountForm.ad_name.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_adName').style.display='';
		document.getElementById('error_adName').innerHTML="Please! Enter Ad Name.";
		return false;
	}

	if(document.myAccountForm.ad_type.value != 'banner')
	{
	if(document.myAccountForm.ad_text.value.search(/\S/) == -1)
	{
		document.getElementById('row_alert_adText').style.display='';
		document.getElementById('error_adText').innerHTML="Please! Enter Ad Text.";
		return false;
	}
	}

	//alert(document.myAccountForm.link_url[0].checked);
 	if(document.myAccountForm.link_url[0].checked == true)
 	{
		if(document.myAccountForm.destinationUrl.value.search(/\S/) == -1)
		{
			document.getElementById('row_alert_linkURL').style.display='';
			document.getElementById('error_adURL').innerHTML="Please! Enter The Link.";
			return false;
		}
		
		
	}

	document.myAccountForm.mode.value='create_advertise';
	document.myAccountForm.submit();
}


function show_mobile_set(id)
{
	//alert(id);
	for(var i =1; i<=4;i++)
	{
// 		if(document.getElementById('content_'+i))
// 		{
			if(i == id)
			{
				//alert('aaa');
				document.getElementById('content_'+i).style.display = 'block';	
			}
			else
			{
				document.getElementById('content_'+i).style.display = 'none';	
			}

		//}
		
	}
	
}


function show_destination_url(val)
{
//alert(val);
	if(val=='lp')
	{
		document.getElementById('link_url_existing_div').style.display='none';
		document.getElementById('link_url_lp_div').style.display='';
	}
	else
	{
		document.getElementById('link_url_existing_div').style.display='';
		document.getElementById('link_url_lp_div').style.display='none';
	}
}
// #########################
function show_text_image()
{
	if(document.getElementById('ad_type').value=='banner')
	{
		document.getElementById('ad_text').style.display='none';
		document.getElementById('text_preview').style.display='none';
		document.getElementById('image_section').style.display='block';
		document.getElementById('preview').style.display='block';
	}
	else
	{
		document.getElementById('image_section').style.display='none';
		document.getElementById('preview').style.display='none';
		document.getElementById('ad_text').style.display='block';
		document.getElementById('text_preview').style.display='block';
	}
}

function preview_text_description_func()
{
document.getElementById("preview_text_description").value = document.getElementById("ad_text").value;
document.getElementById("preview_text_description").innerHTML= document.getElementById("ad_text").value;
document.getElementById("preview_text_description").style.display = 'block';
}

function preview_heading()
{
document.getElementById("prev_heading").value = document.getElementById("ad_name").value;
document.getElementById("prev_heading").innerHTML= document.getElementById("ad_name").value;
document.getElementById("prev_heading").style.display = 'block';
}
</script> 
<script language="javascript" src="js/ajax.js"></script>
<script language="javascript" src="js/ajaxresponse.js"></script>
<script language="javascript" src="JavaScripts/common.js"></script>
<script language="javascript" src="JavaScripts/create_ad.js"></script>
<script language="javascript" src="JavaScripts/ext-base-all.js"></script>
<script language="javascript" src="JavaScripts/TreeCheckNodeUI.js"></script>
<link href="css/global.css" rel="stylesheet" type="text/css">
<link href="css/create_ad.css" rel="stylesheet" type="text/css">
<link href="css/ext-all.css" rel="stylesheet" type="text/css">
<link href="css/ext-all.css" rel="stylesheet" type="text/css">
<link href="css/xtheme-gray.css" rel="stylesheet" type="text/css">
<!--<link rel="stylesheet" href="css/style.css" type="text/css" />-->




<form id="myAccountForm" name="myAccountForm" method="post" action="" onsubmit="return regformvalidation();">

<input type="hidden" name="mode" value="" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="20%" valign="top"><?php include("left_pannel.php"); ?></td>
                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top">

<!-- start Main body -->



<div>Create Ad</div>
	<hr>

			<div> 
      <label for="adSourceBlank" id="adSourceBlankLabel">     Select Ad Type	</label>
	    <select id="ad_type" name="ad_type" onchange="show_text_image()">
	      <option value="text">Text</option>
	      <option value="banner">Banner</option>
	      </select>
	  </div>
	  <br>

    <h3>Ad Text</h3>
  <div id="adText_module">
		<table>
			<tbody>
				<tr id="row_alert_bidPrice" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_bidPrice" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>
				
				<tr>
				<td width="20%">Enter Bid Price: </td>
				<td>

					<input name="bid_price" id="bid_price" size="20" value="" maxlength="30" type="text">
				</td>
				</tr>

				<tr id="row_alert_adName" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_adName" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>

				<tr>
				<td width="15%">Ad Name: </td>
				<td>

					<input name="ad_name" id="ad_name" size="40" value="" maxlength="60" type="text" onkeyup="return preview_heading();">
				</td>
				</tr>

				<tr id="row_alert_adText" style="display:none">
				<td width="20%">&nbsp; </td>
				<td align="left" id="error_adText" style="color:#FF0000; font-weight:bold; font-size:11px;"></td>
				</tr>

				<tr>
				<td width="15%" valign="top">
					Ad Text: </td>
				<td>
				<textarea name="ad_text" class="" id="ad_text" rows="3" cols="35" onkeyup="return preview_text_description_func();"></textarea>
					<!--<input name="ad_text" id="ad_text" size="40" maxlength="35" type="text">-->

          <p>Use the %phn% tag to insert the user's phone model into the text of your ad. (35 char max)</p>
				</td>
			</tr>
			<tr>
				<td valign="top">
					Link To:				</td>
				<td colspan="2">
					<p>

						<input id="link_url_existing" checked="checked" name="link_url" value="existing" type="radio" onclick="show_destination_url(this.value)">
						<label for="link_url_existing">An existing mobile page</label>
					</p>
					<p>
					<input id="link_url_lp" name="link_url" value="lp" type="radio" onclick="show_destination_url(this.value)">
					<label for="link_url_lp">2 in 1 hosted Landing Page</label>
					</p>

					<p>
					<div id="row_alert_linkURL" style="display:none">
					<label class="label" id="error_adURL" style="color:#FF0000; font-weight:bold; font-size:11px;"></label>	
					</div>
					</p>

					<div id="link_url_existing_div">

						<label class="label" for="destinationUrl">Destination URL: </label><br><input name="destinationUrl" id="destinationUrl" value="" type="text">
					</div>

					<div id="link_url_lp_div" style="display: none;">
													You do not have any Landing Pages. <a href="create_landing_page.php">Create a new Landing Page</a> or <a href="#" onclick="">use an existing mobile page</a>.											</div>
				</td>

			</tr>
		</tbody></table>
	</div>

<!-- ################################## div for image starts ########################## -->
<div id="image_section" style="display:none">
  	<h3 class="titleRed"> Image (optional)</h3>
	<div class="x-clear" style="margin-top: 10px;"></div>
    <div style="clear: both;"></div>    <div id="imageErrorContainer" style="display: none;">

      <div align="center"><div style="width: 570px;" class="flashBox errorBox">
  <div class="top">
    <div class="l"><img src="images/spacer.gif"></div>
    <div style="width: 558px;" class="m"><img src="images/spacer.gif"></div>
    <div class="r"><img src="images/spacer.gif"></div>
  </div>
  <div class="mid">
    <table width="570" border="0" cellpadding="0" cellspacing="0" height="100%"><tbody><tr valign="center"><td>
    <div class="l">

      <div style="width: 552px;" class="m">
          <img src="images/error.gif" align="top">         <p id="imageError"></p>
      </div>
    </div>    
    </td></tr></tbody></table>
  </div>

</div></div><div style="clear: both;"></div>    </div>
	<div class="module" id="images_module">
		<table>
			<tbody><tr>
				<td class="label">
					Images</td>

        <td>
          <span class="collapsed" id="imageExpander" >Add or Edit Images</span>
        </td>
      </tr>
    </tbody></table>
<!-- ######################### start ############################### -->

   <!--   <form id="uploadForm" enctype="multipart/form-data" action="http://www.admob.com/my_ads/upload_image/process_upload" method="post">-->
        <table>
          <tbody><tr>
            <td class="label"></td>

  		  		<td>
              <input name="MAX_FILE_SIZE" value="75000" type="hidden">
              <span id="fileInput">
      	<!--<input name="file" id="file" type="file" onchange="return submit_browse_form();">-->
<iframe src="upload.php" align="top"  frameborder="0" scrolling="no" width="390px"  height="110px" allowtransparency="true"></iframe>
              </span>
		 <inpUT type="hidden" name="sahara" value="11">
              <!--<input value="Upload" id="upload" type="submit">-->
  				  </td>
          </tr>
        </tbody></table>

     <!-- </form>-->


	    <div id="imageSections">

                <div id="extraLarge" class="imageElement">
	        <h5>XL - 300x50</h5>
          <img id="xl_img" class="uploaded_image" src="images/bg-grayfade.gif" height="50" width="300">
          <input name="xl_image_url" id="xl_image_url" class="image_url" type="hidden">
	      </div>
        <div class="x-clear"></div>

        <div id="large" class="imageElement">
          <h5>Large - 216x36</h5>
          <img id="l_img" class="uploaded_image" src="images/bg-grayfade.gif" height="36" width="216">
          <input name="l_image_url" id="l_image_url" class="image_url" type="hidden">
        </div>
	<div class="x-clear"></div>


	<div id="medium" class="imageElement">
          <h5>Medium - 168x28</h5>
          <img id="m_img" class="uploaded_image" src="images/bg-grayfade.gif" height="28" width="168">
          <input name="m_image_url" id="m_image_url" class="image_url" type="hidden">
        </div>
        <div class="x-clear"></div>

        <div id="small" class="imageElement">
          <h5>Small - 120x20</h5>
          <img id="s_img" class="uploaded_image" src="images/bg-grayfade.gif" height="20" width="120">
          <input name="s_image_url" id="s_image_url" class="image_url" type="hidden">
        </div>
        <div class="x-clear"></div>

      </div>
 

<!-- ########################### end ########################### -->
  </div>
</div>
<!-- ################################# div for images ends ########################## -->

  <div class="x-clear"></div>
    <span class="step titleRed">3</span><h3 class="titleRed">Select Targeting</h3>

	<div id="targeting_module" class="module">
<?php
$SQL_country="select * from country";
$EXE_country=mysql_query($SQL_country);
?>
    <div class="targeting_label">Country :</div>
		<div id="targeting_options" class="targeting_block">
			<div id="targeting_div_ron" class="targeting_option">

				<select class="" name="country_mobile[]" id="country_mobile" multiple="true">
				<option value="" selected="selected">Select Country</option>
				<?php
				while($ROW_country=mysql_fetch_array($EXE_country))
				{
				?>
				<option value="<?php echo $ROW_country[countries_iso_code_2]; ?>"><?php echo $ROW_country[countryName]?></option>
				<?php
				}
				?>
				</select>
				<!--<input id="targeting_ron" name="targeting" checked="checked" type="radio" value="1" onclick="change_bid(this.value)">-->
				<!--<label id="ext-gen113" for="targeting_ron">All Countries and Carriers</label>-->
			</div>

		</div>

	  <div class="x-clear"></div>

        	</div>


</div>

<br>
<div class="createToolbar">
	<input id="create_ad_submit" value="Create Ad" type="button" align="middle" onclick="create_ad()">
	<!--<input id="create_ad_start_over" value="Start Over" type="button">-->
</div>
<div class="x-clear"></div>






<!-- end Main Body -->

			</d>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table></td>
                    <td width="20%" valign="top">
<!-- ################## right panel starts ################ -->
<div id="caRight">
<!-- ################################# div for ad type(text) to show text starts ############## -->
<div id="text_preview">
<table>
                                <tr valign="top">
                                  <td class="sitename" style="border-right:#cccccc 1px solid;" valign="top" align="center">Preview</td>
                                </tr>
                                <tr>
                                  <td align="center" id="prev_heading"></td>
                                </tr>

                                <tr>
                                  <td align="center" id="preview_text_description"></td>
                                </tr>


                                <?php// if($adtype_retrieve == 'banner'){ ?>
                                <!--<tr>
                                  <td><imG src="upload/<?php// echo $_SESSION[siteuserId]; ?>.<?php// echo $extension[1]; ?>"></td>
                                </tr>-->
                                <?php// } ?>


                                <tr>
                                  <td>Please note: The Preview will not display correctly if you do not set the "Text size" to "Normal" on your browser.</td>
                                </tr>
                              </table>
</div>
<!-- ################################# div for ad type(text) to show text ends ############## -->


<!-- ################################# div for ad type(banner) to show banner image starts ############## -->
	<div id="preview" style="display:none">
    <div class="thirdNavTabs">
			<table border="0" align="left" cellpadding="0" cellspacing="0">
                              <tr>
                                <td id="Nav1" onclick="show_mobile_set(1)"><table border="0" cellspacing="0" cellpadding="0" onMouseOver="Nav1.className='ButtonMiddleBg-Rol'" onMouseOut="Nav1.className='ButtonMiddleBg-Nor'">
                                    <tr>
                                      <td class="ButtonLeftSide">&nbsp;</td>
                                      <td class="ButtonMiddleBg-Nor">S</td>
                                      <td class="ButtonRightSide">&nbsp;</td>
                                    </tr>
                                </table></td>

                                <td id="Nav2" onclick="show_mobile_set(2)"><table border="0" cellspacing="0" cellpadding="0" onMouseOver="Nav2.className='ButtonMiddleBg-Rol'" onMouseOut="Nav2.className='ButtonMiddleBg-Nor'">
                                    <tr>
                                      <td class="ButtonLeftSide">&nbsp;</td>
                                      <td class="ButtonMiddleBg-Nor">M</td>
                                      <td class="ButtonRightSide">&nbsp;</td>
                                    </tr>
                                </table></td>


                                <td id="Nav3" onclick="show_mobile_set(3)"><table border="0" cellspacing="0" cellpadding="0" onMouseOver="Nav3.className='ButtonMiddleBg-Rol'" onMouseOut="Nav3.className='ButtonMiddleBg-Nor'">
                                    <tr>
                                      <td class="ButtonLeftSide">&nbsp;</td>
                                      <td class="ButtonMiddleBg-Nor">L</td>
                                      <td class="ButtonRightSide">&nbsp;</td>
                                    </tr>
                                </table></td>


                                <td id="Nav4" onclick="show_mobile_set(4)"><table border="0" cellspacing="0" cellpadding="0" onMouseOver="Nav4.className='ButtonMiddleBg-Rol'" onMouseOut="Nav4.className='ButtonMiddleBg-Nor'">
                                    <tr>
                                      <td class="ButtonLeftSide">&nbsp;</td>
                                      <td class="ButtonMiddleBg-Nor" id="">XL </td>
                                      <td class="ButtonRightSide">&nbsp;</td>
                                    </tr>
                                </table></td>

                              </tr>
                            </table>
      <div class="x-clear"></div>
		</div>


    <div class="preview_content selected" id="content_1" style="display:block; width:120; height:20">
      <h4>Mobile Web Site</h4>
	
      <img src="images/bg-grayfade.gif">

      <a id="ext-gen109" href="http://cfdf" target="_blank">a</a>
      <p></p>
    </div>


    <div class="preview_content" id="content_2" style="display:none; width:168; height:28;">
      <h4>Mobile Web Site</h4>
      <img src="images/bg-grayfade.gif">
      <a id="ext-gen110" href="http://cfdf" target="_blank">b</a>

      <p></p>
    </div>


    <div class="preview_content" id="content_3" style="display:none; width:216; height:36;">
      <h4>Mobile Web Site</h4>
      <img src="images/bg-grayfade.gif">
      <a id="ext-gen111" href="http://cfdf" target="_blank">c</a>
      <p></p>
    </div>

    <div class="preview_content" id="content_4" style="display:none; width:300; height:50;">
      <h4>Mobile Web Site</h4>
      <img src="images/bg-grayfade.gif">
      <a id="ext-gen112" href="http://cfdf" target="_blank">d</a>
      <p></p>
    </div>

	</div>
<!-- ################################# div for ad type(banner) to show banner image ends############## -->

</div>
<!-- ####################### right pannel ends ################### -->
</td>
                    </tr>
                </table></td>
              </tr>
            </table>
</form>
            
<?php
        //include("footer.php");
}
		?> 